<template>
  <a-card :bordered="false">
    <a-form layout="inline" @keyup.enter.native="searchQuery">
      <a-form-item label="计划编码">
        <a-input v-model="queryParam.itemName" />
      </a-form-item>
      <a-form-item label="计划名称">
        <a-input v-model="queryParam.itemCode" />
      </a-form-item>
      <a-form-item>
        <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
        <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
      </a-form-item>
    </a-form>
    <vxe-grid
      id="PerformancePlan"
      ref="vxeTable"
      v-bind="options"
      :columns="columns"
      :data="dataSource"
      @toolbar-button-click="toolbarButtonClickEvent"
      @checkbox-all="onSelectChange"
      @checkbox-change="onSelectChange"
    >
      <template v-slot:toolbar_buttons>
        <a-button type="primary" icon="plus" style="margin:0px 8px 0px 0px;" @click="handleAdd">新增</a-button>
        <a-dropdown v-if="selectionRows.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
          </a-menu>
          <a-button>批量操作<a-icon type="down" /></a-button>
        </a-dropdown>
      </template>
      <template v-slot:operate="{ row }">
        <a @click="handleEdit(row)">编辑</a>
        <a-divider type="vertical" />
        <a-dropdown>
            <a class="ant-dropdown-link">更多<a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="startInstance(row.planCode)">启动考核</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        <!-- <a-divider type="vertical" />
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
          <a>删除</a>
        </a-popconfirm> -->
      </template>
      <template v-slot:pager>
        <vxe-pager
          :layouts="layouts"
          :current-page.sync="ipagination.currentPage"
          :page-size.sync="ipagination.pageSize"
          :total="ipagination.total"
          @page-change="handlePageChange"
        >
        </vxe-pager>
      </template>
    </vxe-grid>
    <assessment-plan-modal ref="modalForm"  @ok="modalFormOk"/>
  </a-card>
</template>
<script >
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
import AssessmentPlanModal from './modal/AssessmentPlanModal'
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import { filterDictTextByCache } from '@/components/dict/JDictSelectUtil'
import { postActionQs } from '@/api/manage'
export default {
  name: 'AssessmentPlan',
  mixins: [VxeTableMixin],
  components: {
    JSelectUserByDep,
    AssessmentPlanModal
  },
  data() {
    return {
      columns: [
        { type: 'checkbox', width: 50 },
        { type: 'seq', width: 60 },
        { field: 'planCode', title: '考核计划编码' },
        { field: 'planName', title: '考核计划名称' },
        { field: 'accountCycle', title: '绩效周期', slots: { default: ({ row }) => {
          return filterDictTextByCache('hr_account_cycle', row.accountCycle)
        } }},
        { field: 'planType', title: '考核方式', slots: { default: ({ row }) => {
          return filterDictTextByCache('hr_assessment_type', row.planType)
        } }},
        { field: 'selfAble', title: '是否自评', slots: { default: ({ row }) => {
          return row.selfAble ? '是' : '否'
        } }},
        { field: 'remark', title: '备注' },
        { field: 'operate', title: '操作', width: 150, slots: { default: 'operate' }}
      ],
      url: {
        list: '/hr/assessment/plan/list',
        delete: '/hr/assessment/plan/delete',
        deleteBatch: '/hr/assessment/plan/deleteBatch',
        startInstance: '/hr/assessment/instance/startInstance'
      }
    }
  },
  methods: {
    startInstance(planCode) {
      postActionQs(this.url.startInstance, { planCode: planCode }).then(res => {
        if (res.success) {
          this.$message.success('启动成功')
        } else {
          this.$message.warning(res.message)
        }
      })
    }
  }
}
</script>
